CC = gcc
target = ./bin/Debug/all_test
OBJDIR = obj
CFLAGS = -m32 -g -Wall

ifeq ($(PLATFORM),win)
LFLAGS = -m32 -g
LINK_LIB = C:\MinGW\lib\libwinmm.a
else
LFLAGS = -m32 -g -lpthread
endif


INC = -I./protothreads
INC += -I./protothreads/components
INC += -I./protothreads/drivers

ifeq ($(PLATFORM),win)
else
INC += -I./mult_timer
endif


source = $(wildcard *.c)

vpath %.c aaa_sec_fringe
source += $(notdir $(wildcard aaa_sec_fringe/*.c))


ifeq ($(PLATFORM),win)
else
vpath %.c mult_timer
source += $(notdir $(wildcard mult_timer/*.c))
endif


vpath %.c array_func_add_test
source += $(notdir $(wildcard array_func_add_test/*.c))

vpath %.c hello
source += $(notdir $(wildcard hello/*.c))

vpath %.c overflow_test
source += $(notdir $(wildcard overflow_test/*.c))

vpath %.c protothreads
source += $(notdir $(wildcard protothreads/*.c))

vpath %.c protothreads/components
source += $(notdir $(wildcard protothreads/components/*.c))

vpath %.c protothreads/drivers
source += $(notdir $(wildcard protothreads/drivers/*.c))

vpath %.c pt_god_schedule_test
source += $(notdir $(wildcard pt_god_schedule_test/*.c))

vpath %.c pt_completion_test
source += $(notdir $(wildcard pt_completion_test/*.c))

vpath %.c pt_event_set_test
source += $(notdir $(wildcard pt_event_set_test/*.c))

vpath %.c pt_pipe_test
source += $(notdir $(wildcard pt_pipe_test/*.c))

vpath %.c pt_ringbuf_test
source += $(notdir $(wildcard pt_ringbuf_test/*.c))

vpath %.c pt_sem_test
source += $(notdir $(wildcard pt_sem_test/*.c))

vpath %.c pt_soft_timer_thread_test
source += $(notdir $(wildcard pt_soft_timer_thread_test/*.c))

vpath %.c pt_test_mailbox
source += $(notdir $(wildcard pt_test_mailbox/*.c))


vpath %.c pt_test_msgq
source += $(notdir $(wildcard pt_test_msgq/*.c))

vpath %.c pt_workque_test
source += $(notdir $(wildcard pt_workque_test/*.c))


# zzz在后面, aaa在前面, 这样生成的地址就将其他包围住了
vpath %.c zzz_sec_fringe
source += $(notdir $(wildcard zzz_sec_fringe/*.c))

############################################
objs = $(source:%.c=$(OBJDIR)/%.o)

$(target) : $(objs)
	$(CC) -o $@ $^ $(LINK_LIB) $(LFLAGS)

$(objs): $(OBJDIR)/%.o : %.c
	@mkdir -p $(OBJDIR)
	$(CC) -c  $< $(INC) $(CFLAGS) -o $@ 

.PHONY : clean
clean:
ifeq ($(PLATFORM),win)
	rm $(target).exe -f
	rm $(OBJDIR)/*.o -f
else
	find . -name "*.o" | xargs rm -f
	rm $(target) -f
endif